"""
__author__ = 'berlinyoung'
@File   :add_member_page.py
@Date   :2022/5/9 16:48
-*- coding: utf-8 -*-
"""
import yaml
from selenium.webdriver.common.by import By
from weixin_web.step1.po.base import Base

class AddMemberPage(Base):
    # 数据驱动的方法行不通，会把By.ID变成字符串格式导致不能被定位
    # with open("../datas/element_data.yaml", encoding="UTF-8") as f_eles:
    #     eles = yaml.safe_load(f_eles)

    ele_member_add = (By.ID, "memberAdd_acctid","Jinx")
    ele_telphone = (By.CSS_SELECTOR,".ww_telInput_mainNumber","16816881689")
    ele_save_btn = (By.CSS_SELECTOR,".js_btn_save")
    ele_btn_cancel = (By.CSS_SELECTOR,".js_btn_cancel")
    def add_member_success(self,name):
        '''
        添加成员成功，跳转到通讯录页面
        :return:
        '''
        self.find_and_send(By.ID,"username",name)
        self.find_and_send(self.ele_member_add)
        self.find_and_send(self.ele_telphone)
        self.find_and_click(self.ele_save_btn)

        from weixin_web.step1.po.contact_page import ContactPage
        return ContactPage(self.driver)

    def add_member_telphone_fail(self,name):
        '''
        添加成员失败，手机号被占用，跳转到通讯录页面
        :return:
        '''
        self.find_and_send(By.ID, "username", name)
        self.find_and_send(self.ele_member_add)
        self.find_and_send(self.ele_telphone)
        self.find_and_click(self.ele_save_btn)
        tip_list = []
        tips = self.finds(By.CSS_SELECTOR,".ww_inputWithTips_tips")
        for value in tips:
            tip_list.append(value.text)
        print(tip_list)
        self.find_and_click(self.ele_btn_cancel)

        from weixin_web.step1.po.contact_page import ContactPage
        return ContactPage(self.driver)